package com.dai.service;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.ibatis.session.SqlSession;

import com.dai.bean.Product;
import com.dai.dao.productManager;

import com.dai.util.sqlSessionUtil;

/**
 * Servlet implementation class pageServlet
 */
@WebServlet(name = "pageServlet.do", urlPatterns = { "/pageServlet.do" })
public class pageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public pageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
//		request.setAttribute("cate",category);
//		if(category==null){
//			category="";
//		}
		

		doPost(request, response);
		//request.setAttribute("pro", productlist);
		
//		request.getRequestDispatcher("test.jsp").forward(request, response);
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String category=request.getParameter("category");
		SqlSession sqs = sqlSessionUtil.getSqlSession();
		productManager mapper = sqs.getMapper(productManager.class);
		List<Product> productlist = mapper.productlist(category);
		request.setAttribute("List", productlist);
		request.getRequestDispatcher("/product_list.jsp").forward(request, response);
	}

}
